Description: Patch initializes all variables for which GCC gave warnings
    about uninitialized or maybe uninitialized variables.
Author: Sergei Golovan
Last-Modified: Wed, 09 Jul 2014 19:17:02 +0400

--- a/generic/bltArrayObj.c
+++ b/generic/bltArrayObj.c
@@ -69,6 +69,7 @@
     }
     if (nElem%2) {
         if (interp != NULL) {
+	    string = Tcl_GetString(objPtr);
             Tcl_AppendResult(interp, "odd length: ", string, 0);
         }
         return TCL_ERROR;
--- a/generic/bltBgexec.c
+++ b/generic/bltBgexec.c
@@ -559,6 +559,7 @@
 	*lengthPtr = length;
 	return string;
     }
+    *lengthPtr = length;
     return NULL;
 }
 
@@ -603,6 +604,7 @@
 	    return string;
 	}
     }
+    *lengthPtr = 0;
     return NULL;
 }
 /*
--- a/generic/bltTreeCmd.c
+++ b/generic/bltTreeCmd.c
@@ -8086,7 +8086,7 @@
     Blt_TreeKeySearch keyIter;
     int vobjc, kobjc, i, result = TCL_OK, len, cnt = 0, isar;
     int nobreak = 0, noupdate = 0, unset = 0, init = 0, aLen;
-    char *var, *string, *aName, *aPat = NULL;
+    char *var, *string, *aName = NULL, *aPat = NULL;
     int klen, kl, j;
     int *keySet = NULL;
     unsigned int inode;
--- a/generic/bltVector.c
+++ b/generic/bltVector.c
@@ -1896,7 +1896,7 @@
         return TCL_OK;
     }
     for (i=2; i<objc; i+=2) {
-        int option, *ovar;
+        int option, *ovar = NULL;
         if (Tcl_GetIndexFromObj(interp, objv[i], optionArr, "option",
             0, &option) != TCL_OK) {
                 return TCL_OK;
--- a/generic/bltGrAxis.c
+++ b/generic/bltGrAxis.c
@@ -1426,7 +1426,15 @@
 
     nMajor = nMinor = 0;
     majorStep = minorStep = 0.0;
-    if (min < max) {
+    if (min > max) {
+	double m;
+	m = min;
+	min = max;
+	max = m;
+    } else if (min == max) {
+	max = min + 1.0;
+    }
+    /* if (min < max) { */
 	min = (min != 0.0) ? log10(FABS(min)) : 0.0;
 	max = (max != 0.0) ? log10(FABS(max)) : 1.0;
 	
@@ -1474,7 +1482,7 @@
 	     (DEFINED(axisPtr->reqMax)))) {
 	    tickMax = max;
 	}
-    }
+    /* } */
     axisPtr->majorSweep.step = majorStep;
     axisPtr->majorSweep.initial = floor(tickMin);
     axisPtr->majorSweep.nSteps = nMajor;
@@ -1556,7 +1564,15 @@
 
     nTicks = 0;
     tickMin = tickMax = 0.0;
-    if (min < max) {
+    if (min > max) {
+	double m;
+	m = min;
+	min = max;
+	max = m;
+    } else if (min == max) {
+	max = min + 1.0;
+    }
+    /* if (min < max) { */
 	range = max - min;
 	
 	/* Calculate the major tick stepping. */
@@ -1578,7 +1594,7 @@
 	axisMax = tickMax = ceil(max / step) * step + 0.0;
 	
 	nTicks = Round((tickMax - tickMin) / step) + 1;
-    }
+    /* } */
     axisPtr->majorSweep.step = step;
     axisPtr->majorSweep.initial = tickMin;
     axisPtr->majorSweep.nSteps = nTicks;
--- a/generic/bltGrLine.c
+++ b/generic/bltGrLine.c
@@ -3085,8 +3085,9 @@
     register Point2D *pointPtr, *endPtr;
     int i;
 
-    i = -1;			/* Suppress compiler warning. */
+    i = searchPtr->index;
     minDist = searchPtr->dist;
+    closest = searchPtr->point;
     for (linkPtr = Blt_ChainFirstLink(linePtr->traces); linkPtr != NULL;
 	linkPtr = Blt_ChainNextLink(linkPtr)) {
 	tracePtr = Blt_ChainGetValue(linkPtr);
@@ -3140,8 +3141,9 @@
     int i;
     register Segment2D *s;
 
-    i = 0;
+    i = searchPtr->index;
     minDist = searchPtr->dist;
+    closest = searchPtr->point;
     s = linePtr->strips;
     for (count = 0; count < linePtr->nStrips; count++, s++) {
 	dist = (*distProc)(searchPtr->x, searchPtr->y, &(s->p), &(s->q), &b);
--- a/generic/bltBeep.c
+++ b/generic/bltBeep.c
@@ -58,9 +58,7 @@
 	    argv[0], " ?volumePercent?\"", (char *)NULL);
 	return TCL_ERROR;
     }
-    if (argc == 1) {
-	percent = 50;		/* Default setting */
-    } else if (argc == 2) {
+    if (argc == 2) {
 	if (Tcl_GetInt(interp, argv[1], &percent) != TCL_OK) {
 	    return TCL_ERROR;
 	}
@@ -69,6 +67,8 @@
 		argv[1], "\"", (char *)NULL);
 	    return TCL_ERROR;
 	}
+    } else {
+	percent = 50;		/* Default setting */
     }
     XBell(Tk_Display(Tk_MainWindow(interp)), percent);
     return TCL_OK;
--- a/generic/bltConfig.c
+++ b/generic/bltConfig.c
@@ -977,6 +977,7 @@
     int dropOffset;
 
     colorPtr = NULL;
+    color2Ptr = NULL;
     dropOffset = 0;
     if ((string != NULL) && (string[0] != '\0')) {
 	int nElem;
--- a/generic/bltHtext.c
+++ b/generic/bltHtext.c
@@ -3100,6 +3100,8 @@
       forceCopy = 0;
     } else {
       htPtr->last = htPtr->first - 1;
+      lineNum = htPtr->first;
+      lastY = 0;
     }
 
     /* Draw each line */
--- a/generic/bltImage.c
+++ b/generic/bltImage.c
@@ -2738,7 +2738,7 @@
     if (opacity2<0.0) {
         a1 = (1.0 - a2);
     } else {
-        a2 = (opacity2<0.0 ? 0.0 : (opacity2>1.0?1.0:opacity2));
+        a1 = (opacity2<0.0 ? 0.0 : (opacity2>1.0?1.0:opacity2));
     }
     
     for (endPtr = destPtr + count; destPtr < endPtr; srcPtr++, src2Ptr++, destPtr++) {
--- a/generic/bltTabnotebook.c
+++ b/generic/bltTabnotebook.c
@@ -2430,7 +2430,7 @@
     int cavityWidth, cavityHeight;
     int width, height;
     int dx, dy;
-    int x, y;
+    int x = 0, y = 0;
 
     nbPtr = tabPtr->nbPtr;
     pad = nbPtr->inset + nbPtr->inset2;
--- a/generic/bltTabset.c
+++ b/generic/bltTabset.c
@@ -5771,14 +5771,6 @@
      * side when correcting for left/right slants.
      */
     switch (setPtr->side) {
-    case SIDE_TOP:
-    case SIDE_BOTTOM:
-	if (setPtr->slant == SLANT_LEFT) {
-	    x += setPtr->overlap;
-	} else if (setPtr->slant == SLANT_RIGHT) {
-	    x -= setPtr->overlap;
-	}
-	break;
     case SIDE_LEFT:
     case SIDE_RIGHT:
 	if (setPtr->slant == SLANT_LEFT) {
@@ -5787,6 +5779,15 @@
 	    y -= setPtr->overlap;
 	}
 	break;
+    case SIDE_TOP:
+    case SIDE_BOTTOM:
+    default:
+	if (setPtr->slant == SLANT_LEFT) {
+	    x += setPtr->overlap;
+	} else if (setPtr->slant == SLANT_RIGHT) {
+	    x -= setPtr->overlap;
+	}
+	break;
     }
 
     /*
@@ -5817,7 +5818,7 @@
 	iw = imgWidth = ImageWidth(image);
 	ih = imgHeight = ImageHeight(image);
     }
-    img2Width = img2Height = 0;
+    iw2 = ih2 = img2Width = img2Height = 0;
     if (image2 != NULL) {
         iw2 = img2Width = ImageWidth(image2);
         ih2 = img2Height = ImageHeight(image2);
@@ -5847,6 +5848,7 @@
 	tx = x + (tabPtr->screenWidth - tabPtr->textWidth) / 2;
 	break;
     case SIDE_TOP:
+    default:
 	tx = x + (tabPtr->screenWidth - tabPtr->textWidth) / 2;
 	ty = y + dy + tabPtr->iPadY.side1 + IMAGE_PAD;
 	ix = x + (tabPtr->screenWidth - iw) / 2;
@@ -5915,6 +5917,7 @@
         i2x = x + (tabPtr->screenWidth - iw2) / 2;
         break;
     case SIDE_TOP:
+    default:
         i2y = iy + imgHeight + IMAGE_PAD + setPtr->gapLeft;
         i2x = x + (tabPtr->screenWidth - iw2) / 2;
 	break;
--- a/generic/tkButton.c
+++ b/generic/tkButton.c
@@ -1701,7 +1701,7 @@
     GC newGC;
     unsigned long mask;
     Tk_Image image;
-    char *oldTextVar, *oldSelVar;
+    char *oldTextVar = NULL, *oldSelVar = NULL;
     Blt_Tree oldTree;
     int oldNode, result = TCL_OK;
     char * oldABdStr = butPtr->activeBdImageString;
@@ -1721,8 +1721,8 @@
     
     if (Blt_ConfigureWidget(interp, butPtr->tkwin, configSpecs,
 	    argc, argv, (char *)butPtr, flags) != TCL_OK) {
-        if (oldTextVar) ckfree(oldTextVar);
-        if (oldTextVar) ckfree(oldSelVar);
+        if (oldTextVar != NULL) ckfree(oldTextVar);
+        if (oldSelVar != NULL) ckfree(oldSelVar);
 	return TCL_ERROR;
     }
     /*
